package com.logic.landseaserver.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import com.logic.common.exception.BusinessException;
import com.logic.common.security.SecurityUtils;
import com.logic.common.util.QueryUtil;
import com.logic.landseaserver.common.util.DateUtil;
import com.logic.landseaserver.common.util.FopReport;
import com.logic.landseaserver.domain.MonthCompleteWork;
import com.logic.landseaserver.domain.Monthly;
import com.logic.landseaserver.domain.ReportChronicle;
import com.logic.landseaserver.domain.ReportConstructPeople;
import com.logic.landseaserver.domain.ReportConstructPhoto;
import com.logic.landseaserver.domain.ReportConstructSchedule;
import com.logic.landseaserver.domain.ReportData;
import com.logic.landseaserver.domain.ReportDesignEngineer;
import com.logic.landseaserver.domain.ReportFund;
import com.logic.landseaserver.domain.ReportMaterial;
import com.logic.landseaserver.domain.ReportPeopleNumber;
import com.logic.landseaserver.domain.Weather;
import com.logic.landseaserver.domain.WeekCompleteWork;
import com.logic.landseaserver.domain.Weekly;
import com.logic.landseaserver.persistence.read.MonthCompleteWorkReadMapper;
import com.logic.landseaserver.persistence.read.MonthlyReadMapper;
import com.logic.landseaserver.persistence.read.RemouldProjectReadMapper;
import com.logic.landseaserver.persistence.read.ReportChronicleReadMapper;
import com.logic.landseaserver.persistence.read.ReportConstructPeopleReadMapper;
import com.logic.landseaserver.persistence.read.ReportConstructPhotoReadMapper;
import com.logic.landseaserver.persistence.read.ReportConstructScheduleReadMapper;
import com.logic.landseaserver.persistence.read.ReportDesignEngineerReadMapper;
import com.logic.landseaserver.persistence.read.ReportFundReadMapper;
import com.logic.landseaserver.persistence.read.ReportMaterialReadMapper;
import com.logic.landseaserver.persistence.read.ReportPeopleNumberReadMapper;
import com.logic.landseaserver.persistence.read.WeatherReadMapper;
import com.logic.landseaserver.persistence.read.WeekCompleteWorkReadMapper;
import com.logic.landseaserver.persistence.read.WeeklyReadMapper;
import com.logic.landseaserver.persistence.write.MonthCompleteWorkWriteMapper;
import com.logic.landseaserver.persistence.write.MonthlyWriteMapper;
import com.logic.landseaserver.persistence.write.ReportChronicleWriteMapper;
import com.logic.landseaserver.persistence.write.ReportConstructPeopleWriteMapper;
import com.logic.landseaserver.persistence.write.ReportConstructPhotoWriteMapper;
import com.logic.landseaserver.persistence.write.ReportConstructScheduleWriteMapper;
import com.logic.landseaserver.persistence.write.ReportDesignEngineerWriteMapper;
import com.logic.landseaserver.persistence.write.ReportFundWriteMapper;
import com.logic.landseaserver.persistence.write.ReportMaterialWriteMapper;
import com.logic.landseaserver.persistence.write.ReportPeopleNumberWriteMapper;
import com.logic.landseaserver.persistence.write.WeatherWriteMapper;
import com.logic.landseaserver.persistence.write.WeekCompleteWorkWriteMapper;
import com.logic.landseaserver.persistence.write.WeeklyWriteMapper;
import com.logic.landseaserver.service.IRemouldProjectReportService;
import com.logic.landseaserver.ws.dto.MonthWeekDayReportDTO;
import com.logic.landseaserver.ws.dto.MonthlyDTO;
import com.logic.landseaserver.ws.dto.PropertyDTO;
import com.logic.landseaserver.ws.dto.QueryMonthDTO;
import com.logic.landseaserver.ws.dto.QueryMonthWeekDayReport;
import com.logic.landseaserver.ws.dto.QueryRemouldProjectReportDTO;
import com.logic.landseaserver.ws.dto.QueryWeekDTO;
import com.logic.landseaserver.ws.dto.QueryYearDTO;
import com.logic.landseaserver.ws.dto.RemouldProjectDTO;
import com.logic.landseaserver.ws.dto.WeekDayReportDTO;
import com.logic.landseaserver.ws.dto.WeekReportDTO;
import com.logic.landseaserver.ws.dto.WeeklyDTO;
import com.logic.landseaserver.ws.dto.YearMonthDayReportDTO;
import com.logic.system.domain.SystemFile;
import com.logic.system.persistence.read.FileReadMapper;
import com.logic.system.service.impl.AddressService;
import com.logic.system.ws.dto.AddressDto;


@Service
public class RemouldProjectReportServiceImpl implements IRemouldProjectReportService,EnvironmentAware{
    
    private Logger logger = LoggerFactory.getLogger(PDFGenerationServiceImpl.class);
    private static RelaxedPropertyResolver propertyResolver;
    private static final String ENV_FILE_PATH = "logic.file.path.";
    private static final String LOCAL_PATH = "local";
    private static final String REMOTE_PATH = "remote";
    //private static final MonthCompleteWork reportDesignEngineer2 = null;
    
    private String localPath = null;
    private String remotePath = null;
    
    @Autowired 
    private WeeklyReadMapper weeklyReadMapper;
    
    @Autowired 
    private WeeklyWriteMapper weeklyWriteMapper;
    
    @Autowired 
    private WeatherWriteMapper weatherWriteMapper;
    
    @Autowired 
    private RemouldProjectReadMapper remouldProjectReadMapper;
    
    @Autowired 
    private AddressService addressService;
    
    @Autowired 
    private WeekCompleteWorkWriteMapper weekCompleteWorkWriteMapper;
    
    @Autowired 
    private ReportMaterialWriteMapper reportMaterialWriteMapper;
    
    @Autowired 
    private ReportPeopleNumberWriteMapper reportPeopleNumberWriteMapper;
    
    @Autowired 
    private ReportChronicleWriteMapper reportChronicleWriteMapper;
    
    
    @Autowired 
    private ReportConstructScheduleWriteMapper reportConstructScheduleWriteMapper;
    
    @Autowired 
    private MonthlyWriteMapper monthlyWriteMapper;
    
    @Autowired 
    private MonthCompleteWorkWriteMapper monthCompleteWorkWriteMapper;
    
    @Autowired 
    private ReportFundWriteMapper reportFundWriteMapper;
    
    @Autowired 
    private ReportDesignEngineerWriteMapper reportDesignEngineerWriteMapper;
    
    @Autowired 
    private ReportConstructPeopleWriteMapper reportConstructPeopleWriteMapper;
    
    @Autowired 
    private ReportConstructPhotoWriteMapper reportConstructPhotoWriteMapper;
    
    @Autowired 
    private MonthlyReadMapper monthlyReadMapper;
    
    @Autowired 
    private WeatherReadMapper weatherReadMapper;
    
    @Autowired 
    private WeekCompleteWorkReadMapper weekCompleteWorkReadMapper;
    
    @Autowired 
    private ReportMaterialReadMapper reportMaterialReadMapper;
    
    @Autowired 
    private ReportPeopleNumberReadMapper reportPeopleNumberReadMapper;
    
    @Autowired 
    private ReportChronicleReadMapper reportChronicleReadMapper;
    
    @Autowired 
    private ReportConstructScheduleReadMapper reportConstructScheduleReadMapper;
    
    @Autowired 
    private MonthCompleteWorkReadMapper monthCompleteWorkReadMapper;
    
    @Autowired 
    private ReportFundReadMapper reportFundReadMapper;
    
    @Autowired 
    private ReportDesignEngineerReadMapper reportDesignEngineerReadMapper;
    
    @Autowired 
    private ReportConstructPeopleReadMapper reportConstructPeopleReadMapper;
    
    @Autowired 
    private ReportConstructPhotoReadMapper reportConstructPhotoReadMapper;

    @Autowired 
    private FileReadMapper fileReadMapper;
    
    @Override
    public void delete(String arg0) throws BusinessException {
        // TODO Auto-generated method stub
        
    }
    
    @Override
    public Object get(Integer arg0) throws BusinessException {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public List<?> query(QueryUtil arg0) {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public void update(Object arg0) throws BusinessException {
        // TODO Auto-generated method stub
        
    }
    
    @Override
    public Boolean validate(Object arg0) throws BusinessException {
        Boolean pass = true;
        return pass;
    }
    
    @Override
    public Boolean validateForDelete(Object arg0) throws BusinessException {
        // TODO Auto-generated method stub
        return null;
    }
    
    public Boolean validateForInsertWeekly(Weekly weekly) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(weekly);
        return pass;
    }
    
    public Boolean validateForInsertWeather(Weather weather) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(weather);
        return pass;
    }
    
    public Boolean validateForInsertWeekCompleteWork(WeekCompleteWork weekCompleteWork) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(weekCompleteWork);
        return pass;
    }
    
    public Boolean validateForInsertReportMaterial(ReportMaterial reportMaterial) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportMaterial);
        return pass;
    }
    
    public Boolean validateForInsertReportPeopleNumber(ReportPeopleNumber reportPeopleNumber) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportPeopleNumber);
        return pass;
    }
    
    public Boolean validateForInsertReportChronicle(ReportChronicle reportChronicle) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportChronicle);
        return pass;
    }
    
    public Boolean validateForInsertReportConstructSchedule(ReportConstructSchedule reportConstructSchedule) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportConstructSchedule);
        return pass;
    }
    
    public Boolean validateForInsertMonthly(Monthly monthly) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(monthly);
        return pass;
    }
    
    public Boolean validateForInsertMonthCompleteWork(MonthCompleteWork monthCompleteWork) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(monthCompleteWork);
        return pass;
    }
    
    public Boolean validateForInsertReportFund(ReportFund reportFund) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportFund);
        return pass;
    }
    
    public Boolean validateForInsertReportDesignEngineer(ReportDesignEngineer reportDesignEngineer) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportDesignEngineer);
        return pass;
    }
    
    public Boolean validateForInsertReportConstructPeople(ReportConstructPeople reportConstructPeople) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportConstructPeople);
        return pass;
    }
    
    public Boolean validateForInsertReportConstructPhoto(ReportConstructPhoto reportConstructPhoto) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(reportConstructPhoto);
        return pass;
    }
    
    @Override
    public Boolean validateForInsert(Object arg0) throws BusinessException {
        Boolean pass = false;
        pass = this.validate(arg0);
        return pass;
    }
    
    @Override
    public Boolean validateForUpdate(Object arg0) throws BusinessException {
        // TODO Auto-generated method stub
        return null;
    }
    
    private void buildAddressDTO(PropertyDTO propertyDTO) {
        Integer addressId = propertyDTO.getAddressId();
        if (addressId != null) {
            StringBuffer fullName = new StringBuffer();
            AddressDto addressDto = addressService.queryDetailById(addressId);
            if(addressDto != null) {
                String province = addressDto.getProvince();
                String city = addressDto.getCity();
                String county = addressDto.getCounty();
                String addressLine = addressDto.getAddressLine();
                fullName.append(province == null ? "" : province).append(city == null ? "" : city).append(county == null ? "" : county)
                .append(addressLine == null ? "" : addressLine);
                addressDto.setFullAddress(fullName.toString());
                propertyDTO.setAddressDto(addressDto);
            }
        }
    }
    
    @Override
    public WeekReportDTO getWeekReportDTO(Integer remouldProjectId) {
        RemouldProjectDTO remouldProjectDTO = remouldProjectReadMapper.selectDTOByPrimaryKey(remouldProjectId);
        PropertyDTO propertyDTO = remouldProjectDTO.getPropertyDTO();
        if (remouldProjectDTO != null && propertyDTO != null) {
            buildAddressDTO(propertyDTO);
        }
        WeekReportDTO weekReportDTO = weeklyReadMapper.getWeekReportDTO(remouldProjectId);
        weekReportDTO.setProjectAddress(propertyDTO);
        return weekReportDTO;
    }
    
    
    @Override
    public int insert(Object arg0) throws BusinessException {
        int i =0 ;
        return i;
    } 
    
    @SuppressWarnings("unused")
    @Override
    public int insertWeekly(Weekly weekly) throws BusinessException, Exception {
        Integer id = -1;
        Boolean pass = this.validateForInsertWeekly(weekly);
        if (pass) {
            weekly.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            DateUtil dateUtil = new DateUtil(); 
            Integer remouldProjectId = weekly.getRemouldProjectId();
            String type = weekly.getType();
            if ("2".equals(type))
            {
                String month = weekly.getMonth();
                Integer week = weekly.getWeek();
                HashMap<String , Object> monthMap = new HashMap<String , Object>(); 
                monthMap.put("remouldProjectId", remouldProjectId);
                monthMap.put("month", month);
                monthMap.put("week", week);
                Weekly weekly2 = weeklyReadMapper.selectByWeek(monthMap);
                if (weekly2 != null)
                {
                    return -100;
                }
                else{
                    String year = month.substring(0, 3);
                    Integer year1 = Integer.parseInt(year);
                    String month2 = month.substring(5);
                    Integer month3 = 0;
                    if (0 == Integer.parseInt(month2.substring(0, 1)))
                    {
                        month3 = Integer.parseInt(month2.substring(1));
                    }
                    else{
                        month3 = Integer.parseInt(month2);
                    }
                    weekly.setTotalWeekOfYear(dateUtil.getWeekOfYear(dateUtil.getDateByWeek(year1, month3, week)));
                    id = weeklyWriteMapper.insertSelective(weekly);
                }
            }
            else if ("1".equals(type)) {
                Date d = new Date();
                
                String  day = weekly.getDate();
                Weekly day1 = weeklyReadMapper.selectDayByTime(day,remouldProjectId); 
                if (day1 != null)
                {
                    return -100;
                }
                else{
                    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd");

                       Date date =   sdf.parse(day);
                        weekly.setWeek(dateUtil.getWeekOfMonth(date));
                        weekly.setTotalWeekOfYear(dateUtil.getWeekOfYear(date));
                    id = weeklyWriteMapper.insertSelective(weekly);
                }
            }
            
        }
        return weekly.getId();
    }
    
    @Override
    public int insertWeather(Weather weather) throws BusinessException{
        Integer id = -1;
        Boolean pass = this.validateForInsertWeather(weather);
        if (pass) {
            weather.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id = weatherWriteMapper.insertSelective(weather);
            
        }
        return id;
    }
    
    @Override
    public int insertWeekCompleteWork(WeekCompleteWork weekCompleteWork) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertWeekCompleteWork(weekCompleteWork);
        if (pass) {
            weekCompleteWork.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id = weekCompleteWorkWriteMapper.insertSelective(weekCompleteWork);
            
        }
        return id;
    }
    
    @Override
    public int insertReportMaterial(ReportMaterial reportMaterial) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportMaterial(reportMaterial);
        if (pass) {
            reportMaterial.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id = reportMaterialWriteMapper.insertSelective(reportMaterial);
            
        }
        return id;
    }
    
    @Override
    public int insertReportPeopleNumber(ReportPeopleNumber reportPeopleNumber) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportPeopleNumber(reportPeopleNumber);
        if (pass) {
            reportPeopleNumber.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id = reportPeopleNumberWriteMapper.insertSelective(reportPeopleNumber);
            
        }
        return id;
    }
    
    @Override
    public int insertReportChronicle(ReportChronicle reportChronicle) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportChronicle(reportChronicle);
        if (pass) {
            reportChronicle.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id = reportChronicleWriteMapper.insertSelective(reportChronicle);
            
        }
        return id;
    }
    
    @Override
    public int insertReportConstructSchedule(ReportConstructSchedule reportConstructSchedule) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportConstructSchedule(reportConstructSchedule);
        if (pass) {
            reportConstructSchedule.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id = reportConstructScheduleWriteMapper.insertSelective(reportConstructSchedule);
        }
        return id;
    }
    
    @SuppressWarnings("unused")
    @Override
    public int insertMonthly(Monthly monthly) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertMonthly(monthly);
        if (pass) {
            monthly.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            Date date = new Date();
            DateUtil dateUtil = new DateUtil();
            String month = monthly.getMonth();
            HashMap<String , Object> monthMap = new HashMap<String , Object>(); 
            monthMap.put("month", month);
            monthMap.put("remouldProjectId", monthly.getRemouldProjectId());
            Monthly monthly2 = monthlyReadMapper.selectByMonth(monthMap);
            if (monthly2 != null)
            {
                return -100;
            }
            else{
                id = monthlyWriteMapper.insertSelective(monthly);
            }   
        }
        return monthly.getId();
    }
    
    @Override
    public int insertMonthCompleteWork(MonthCompleteWork monthCompleteWork) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertMonthCompleteWork(monthCompleteWork);
        if (pass) {
            monthCompleteWork.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id =monthCompleteWorkWriteMapper.insertSelective(monthCompleteWork);
        }
        return id;
    }
    
    @Override
    public int insertReportReportFund(ReportFund reportFund) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportFund(reportFund);
        if (pass) {
            reportFund.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id =reportFundWriteMapper.insertSelective(reportFund);
        }
        return id;
    }
    
    @Override
    public int insertReportDesignEngineer(ReportDesignEngineer reportDesignEngineer) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportDesignEngineer(reportDesignEngineer);
        if (pass) {
            reportDesignEngineer.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id =reportDesignEngineerWriteMapper.insertSelective(reportDesignEngineer);
        }
        return id;
    }
    
    @Override
    public int insertReportConstructPeople(ReportConstructPeople reportConstructPeople) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportConstructPeople(reportConstructPeople);
        if (pass) {
            reportConstructPeople.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id =reportConstructPeopleWriteMapper.insertSelective(reportConstructPeople);
        }
        return id;
    }
    
    @Override
    public int insertReportConstructPhoto(ReportConstructPhoto reportConstructPhoto) throws BusinessException {
        Integer id = -1;
        Boolean pass = this.validateForInsertReportConstructPhoto(reportConstructPhoto);
        if (pass) {
            reportConstructPhoto.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            id =reportConstructPhotoWriteMapper.insertSelective(reportConstructPhoto);
        }
        return id;
    }
    
    @Override
    public YearMonthDayReportDTO getYearMonthDayReportDTO(Integer id)
    {
        YearMonthDayReportDTO dto = new YearMonthDayReportDTO();
        Date date = new Date();
        DateUtil dateUtil = new DateUtil();
        String month = dateUtil.convertMonth(date);
        String day = dateUtil.convertDate(date);
        dto.setMonth(month);
        dto.setDay(day);
        String week = dateUtil.getWeekOfMonth(date)+"";
        dto.setWeek(week);
        List<Monthly> monthlies = monthlyReadMapper.selectByRemouldProjectId(id);
        for (Monthly monthly : monthlies)
        {
            String month1 = dateUtil.convertMonth(monthly.getCreatedDtm());
            if (month.equals(month1))
            {
                String monthStatus = monthly.getStatus();
                if ("R181".equals(monthStatus))
                {
                    dto.setMonthStatus("草稿");
                }
                else if ("R182".equals(monthStatus))
                {
                    dto.setMonthStatus("待审核");
                }
                else if ("R183".equals(monthStatus))
                {
                    dto.setMonthStatus("通过");
                }
                else if ("R184".equals(monthStatus))
                {
                    dto.setMonthStatus("驳回");
                }
            }
        }
        List<Weekly> weeklies = weeklyReadMapper.selectByRemouldProjectId(id);
        for (Weekly weekly : weeklies)
        {
            String month2 = dateUtil.convertMonth(weekly.getCreatedDtm());
            if (month.equals(month2))
            {
                Integer tw = dateUtil.getWeekOfYear(date);
                if (tw.equals(weekly.getTotalWeekOfYear()))
                {
                    String weekStatus = weekly.getStatus();
                    if ("R181".equals(weekStatus))
                    {
                        dto.setWeekStatus("草稿");
                    }
                    else if ("R182".equals(weekStatus))
                    {
                        dto.setWeekStatus("待审核");
                    }
                    else if ("R183".equals(weekStatus))
                    {
                        dto.setWeekStatus("通过");
                    }
                    else if ("R184".equals(weekStatus))
                    {
                        dto.setWeekStatus("驳回");
                    }
                    dto.setTotalWeek(tw);
                }
            }
        }
        List<Weekly> days = weeklyReadMapper.selectByRemouldProjectIdOfWeek(id);
        for (Weekly weekly : days)
        {
            String day1 = dateUtil.convertDate(weekly.getCreatedDtm());
            if (day.equals(day1))
            {
                String dayStatus = weekly.getStatus();
                if ("R181".equals(dayStatus))
                {
                    dto.setDayStatus("草稿");
                }
                else if ("R182".equals(dayStatus))
                {
                    dto.setDayStatus("待审核");
                }
                else if ("R183".equals(dayStatus))
                {
                    dto.setDayStatus("通过");
                }
                else if ("R184".equals(dayStatus))
                {
                    dto.setDayStatus("驳回");
                }
            }
        }
        return dto;
    }
    
    @Override
    public void deleteMonthReport(Integer id)
    {
        monthlyWriteMapper.deleteByPrimaryKey(id);
        weatherWriteMapper.deleteByMonthId(id);
        reportChronicleWriteMapper.deleteByMonthId(id+"");
        monthCompleteWorkWriteMapper.deleteByMonthId(id);
        reportConstructScheduleWriteMapper.deleteByMonthId(id);
        reportMaterialWriteMapper.deleteByMonthId(id+"");
        reportFundWriteMapper.deleteByMonthId(id);
        reportDesignEngineerWriteMapper.deleteByMonthId(id);
        reportConstructPeopleWriteMapper.deleteByMonthId(id);
        reportConstructPhotoWriteMapper.deleteByMonthId(id);
    }
    
    @Override
    public void deleteWeekReport(Integer id)
    {
        weeklyWriteMapper.deleteByPrimaryKey(id);
        weatherWriteMapper.deleteByWeekId(id);
        weekCompleteWorkWriteMapper.deleteByWeekId(id);
        reportMaterialWriteMapper.deleteByWeekId(id+"");
        reportPeopleNumberWriteMapper.deleteByWeekId(id);
        reportChronicleWriteMapper.deleteByWeekId(id+"");
        reportConstructScheduleWriteMapper.deleteByWeekId(id);
    }
    
    @Override
    public void deleteDayReport(Integer id)
    {
        weeklyWriteMapper.deleteById(id);
        weatherWriteMapper.deleteByDayId(id);
        weekCompleteWorkWriteMapper.deleteByDayId(id);
        reportMaterialWriteMapper.deleteByDayId(id+"");
        reportPeopleNumberWriteMapper.deleteByDayId(id);
        reportChronicleWriteMapper.deleteByDayId(id+"");
        reportConstructScheduleWriteMapper.deleteByDayId(id);
        
    }
    
    @Override
    public List<String> selectYearByType(QueryYearDTO dto)
    {
        List<String> years = new ArrayList<>();
        String type = dto.getType();
        //月报
        if ("3".equals(type))
        {
            years = monthlyReadMapper.selectByType(dto.getRemuldProjectId());
        }
        //周报
        else if ("2".equals(type))
        {
            years = weeklyReadMapper.selectByType(dto);
        }
        //日报
        else if ("1".equals(type)) {
            years = weeklyReadMapper.selectByType(dto);
        }
        
        return years;
    }
    
    @Override
    public List<String> selectMonthByType(QueryMonthDTO dto)
    {
        List<String> month = new ArrayList<>();
        String type = dto.getType();
        //月报
        if ("3".equals(type))
        {
            month = monthlyReadMapper.selectByType1(dto);
        }
        //周报
        else if ("2".equals(type))
        {
            month = weeklyReadMapper.selectByType1(dto);
        }
        //日报
        else if ("1".equals(type)) {
            month = weeklyReadMapper.selectByType1(dto);
        }
        
        return month;
    }
    
    @Override
    public List<String> selectWeekByType(QueryWeekDTO dto)
    {
        List<String> week = new ArrayList<>();
        String type = dto.getType();
        //月报
        //        if ("3".equals(type))
        //        {
        //            week = monthlyReadMapper.selectByType2(dto);
        //        }
        //周报
        if ("2".equals(type))
        {
            week = weeklyReadMapper.selectByType2(dto);
        }
        //日报
        else if ("1".equals(type)) {
            week = weeklyReadMapper.selectByType2(dto);
        }
        
        return week;
    }
   
    //条件查询（主要根据type）
    @Override
    public List<QueryMonthWeekDayReport> queryListDTO(QueryRemouldProjectReportDTO dto)
    {
        List<QueryMonthWeekDayReport> results = new ArrayList<QueryMonthWeekDayReport>(); 
        String type = dto.getType();
        if (type != null)
        {
            QueryMonthWeekDayReport queryMonthWeekDayReport = new QueryMonthWeekDayReport();
            if ("3".equals(type))
            {
                
                List<MonthlyDTO> monthlies = monthlyReadMapper.select(dto);
                queryMonthWeekDayReport.setMonthlyDTOs(monthlies);
                results.add(queryMonthWeekDayReport);
            }
            else if ("2".equals(type))
            {
                List<WeeklyDTO> weeklies = weeklyReadMapper.select(dto);
                queryMonthWeekDayReport.setWeeklyDTOs(weeklies);;
                results.add(queryMonthWeekDayReport);
            }
            else if ("1".equals(type))
            {
                List<WeeklyDTO> weeklies = weeklyReadMapper.select(dto);
                queryMonthWeekDayReport.setDayDTOs(weeklies);;
                results.add(queryMonthWeekDayReport);
            }
        }
        return results;
    }
    //不用type来查
    @Override
    public List<MonthWeekDayReportDTO> queryListDTOWithoutType(QueryRemouldProjectReportDTO dto)
    {
        List<MonthWeekDayReportDTO> results = new ArrayList<MonthWeekDayReportDTO>(); 
       // DateUtil dateUtil = new DateUtil();
        //查出月报
        List<Monthly> monthlies = monthlyReadMapper.selectByDTO(dto);
        List<MonthWeekDayReportDTO> monthWeekDayReportDTOs = new ArrayList<>();
        
        Set<String> set = new HashSet<>();
        
        for (Monthly monthly : monthlies)
        {
            set.add(monthly.getMonth());      
        }
            for (String month : set)
            {
                MonthWeekDayReportDTO monthWeekDayReportDTO = new MonthWeekDayReportDTO();
                //根据月报查出所有当月的所以周报
                dto.setType("2");
                List<Weekly> weeklies = weeklyReadMapper.selectByDTO(dto);
                List<WeekDayReportDTO> weekDayReportDTOs = new ArrayList<>();
                
                for (Weekly weekly : weeklies)
                {
                    String month1 = weekly.getMonth();
                    Set<Integer> set1 = new HashSet<>();
                    if (month.equals(month1))
                    {
                        Integer week = weekly.getWeek();
                        set1.add(week);
                        
                    }
                    for (Integer week1 : set1)
                    {
                        WeekDayReportDTO weekDayReportDTO = new WeekDayReportDTO();
                        //根据周查出日报
                        dto.setType("1");
                        List<Weekly> dayDTOs = weeklyReadMapper.selectByDTO(dto);
                        List<Weekly> days1 = new ArrayList<>();
                        for (Weekly weekly2 : dayDTOs)
                        {
                            Integer week = weekly2.getWeek();
                            Weekly weekly3 = new Weekly();
                            if (week1.equals(week))
                            {
                                weekly3 = weekly2;
                                days1.add(weekly3);
                                weekDayReportDTO.setDay(days1);
                            }       
                        }
                        //根据周获取周报id
                        HashMap<String , Object> weekMap = new HashMap<>();
                        weekMap.put("month",weekly.getMonth() );
                        weekMap.put("remouldPrjectId", dto.getRemouldProjectId());
                        weekMap.put("week", weekly.getWeek());
                        Weekly weekly2 = weeklyReadMapper.selectByWeek(weekMap);
                        weekDayReportDTO.setWeek(week1);
                        weekDayReportDTO.setId(weekly2.getId());
                        weekDayReportDTOs.add(weekDayReportDTO);
                    }  
                }
                //根据年月获取月报id
                HashMap<String , Object> monthMap = new HashMap<>();
                monthMap.put("month",month );
                monthMap.put("remouldProjectId", dto.getRemouldProjectId());
                //根据年月获取月报id
                Monthly monthly = monthlyReadMapper.selectByMonth(monthMap);
                
                Integer   id1 = monthly.getId();
                
                monthWeekDayReportDTO.setId(id1);
                monthWeekDayReportDTO.setMonth(month); 
                monthWeekDayReportDTO.setWeekDayReportDTO(weekDayReportDTOs);
                monthWeekDayReportDTOs.add(monthWeekDayReportDTO);
                results.add(monthWeekDayReportDTO);
            }
        
        return results;
    }
    
    //生成pdf
    @Override
    public String getReportWeekPDF(int id) throws IOException
    {
        String pdf_url = null;
        StringBuffer pdfFileName = new StringBuffer();
        pdfFileName
        .append("WeekReport").append("-").append(System.currentTimeMillis()).append(".pdf");
        pdf_url = getPDFRemotePath(pdfFileName.toString());
        DateUtil dateUtil = new DateUtil();
        WeeklyDTO weeklyDTO = weeklyReadMapper.selectPrimaryKey(id);
        //取出时间
        Date createdDtm = weeklyDTO.getCreatedDtm();
        // String year = dateUtil.convertYear(createdDtm);
        String month = dateUtil.getMm(createdDtm);
        String day = dateUtil.getDd(createdDtm);
        Date createdDtm1 = dateUtil.getLastSevenDayTime(createdDtm);
        Date createdDtm2 = dateUtil.getNextSevenDayTime(createdDtm);
        String month1 = dateUtil.getMm(createdDtm1);
        String day1 = dateUtil.getDd(createdDtm1);
        String year1 = dateUtil.convertYear(createdDtm1);
        String month2 = dateUtil.getMm(createdDtm2);
        String day2 = dateUtil.getDd(createdDtm2);
        
        Integer remouldProjectId = weeklyDTO.getRemouldProjectId();
        WeekReportDTO weekReportDTO = weeklyReadMapper.getWeekReportDTO(remouldProjectId);
        //取出编号
        String serialNum = weekReportDTO.getSerialNum();
        
        Weather weather = weatherReadMapper.selectByWeeklyId(id);
        Integer sun = weather.getSunny();
        Integer cloudy = weather.getCloudy();
        Integer rain = weather.getRain();
        List<WeekCompleteWork> weekCompleteWork = weekCompleteWorkReadMapper.selectByWeeklyId(id);
        List<ReportMaterial> reportMaterial = reportMaterialReadMapper.selectByWeeklyId(id+"");
        
        ReportPeopleNumber reportPeopleNumber = reportPeopleNumberReadMapper.selectByWeeklyId(id);
        ReportChronicle reportChronicle = reportChronicleReadMapper.selectByWeeklyId(id+"");
        List<ReportConstructSchedule> reportConstructSchedule = reportConstructScheduleReadMapper.selectByWeeklyId(id);
        
        //填充数据
        StringBuffer buf = new StringBuffer();
        buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        buf.append("<weekReport>");
        
        buf.append(" <ReportHeader>");
        buf.append("<Title>");
        buf.append("<RemouldProjectName><![CDATA[" +this.null2Blank(weekReportDTO.getName()) + "]]></RemouldProjectName>");
        buf.append("</Title>");
        buf.append(" </ReportHeader>");
        
        buf.append("<ReportTime>");
        buf.append("<Time>");
        buf.append("<Year1><![CDATA[" +this.null2Blank(year1) + "]]></Year1>");
        buf.append("<Month1><![CDATA[" +this.null2Blank(month1) + "]]></Month1>");
        buf.append("<Day1><![CDATA[" +this.null2Blank(day1) + "]]></Day1>");
        buf.append("<Month2><![CDATA[" +this.null2Blank(month) + "]]></Month2>");
        buf.append("<Day2><![CDATA[" +this.null2Blank(day) + "]]></Day2>");
        buf.append("<SerialNum><![CDATA[" +this.null2Blank(serialNum) + "]]></SerialNum>");
        buf.append("</Time>");
        buf.append("</ReportTime>");
        
        buf.append("<ReportWeather>");
        buf.append("<Weather>");
        buf.append("<Sun><![CDATA[" +this.null2Blank(sun+"") + "]]></Sun>");
        buf.append("<Cloudy><![CDATA[" +this.null2Blank(cloudy+"") + "]]></Cloudy>");
        buf.append("<Rain><![CDATA[" +this.null2Blank(rain+"") + "]]></Rain>");
        buf.append("</Weather>");
        buf.append("</ReportWeather>");
        
        buf.append("<WeekCompleteWork1>");
        buf.append("<Title>本周各部分项工程完成情况</Title>");
        buf.append("</WeekCompleteWork1>");
        
        buf.append("<WeekCompleteWork>");
        Integer i = 0;
        if (weekCompleteWork != null && weekCompleteWork.size() > 0) {
            
            for (WeekCompleteWork weekCompleteWork2 : weekCompleteWork)
            {
                i++;
                buf.append("<Record>"
                    + "<number><![CDATA[" + this.null2Blank(i+"") + "]]></number>"
                    +"<remouldProjectName><![CDATA[" + this.null2Blank(weekReportDTO.getName()) + "]]></remouldProjectName>"
                    + "<constructContent><![CDATA[" + this.null2Blank(weekCompleteWork2.getConstructContent()) + "]]></constructContent>"
                    +"<constructUnit><![CDATA[" + this.null2Blank(weekReportDTO.getConstructUnit()) + "]]></constructUnit>"
                    + "<plannCompleteWork><![CDATA[" + this.null2Blank(weekCompleteWork2.getPlannCompleteWork()+"") + "]]></plannCompleteWork>"
                    + "<actualCompleteWork><![CDATA[" + this.null2Blank(weekCompleteWork2.getActualCompleteWork()+"") + "]]></actualCompleteWork>"
                    + "<comment><![CDATA[" + this.null2Blank(weekCompleteWork2.getComment()) + "]]></comment>"
                    + "</Record>");
            }  
        }
        buf.append("</WeekCompleteWork>");
        
        buf.append("<reportConstructSchedule1>");
        buf.append("<Title>下周的施工进度计划表</Title>");
        buf.append("</reportConstructSchedule1>");
        
        buf.append("<reportConstructSchedule>");
        buf.append("<Time>");
        buf.append("<Month1><![CDATA[" +this.null2Blank(month) + "]]></Month1>");
        buf.append("<Day1><![CDATA[" +this.null2Blank(day) + "]]></Day1>");
        buf.append("<Month2><![CDATA[" +this.null2Blank(month2) + "]]></Month2>");
        buf.append("<Day2><![CDATA[" +this.null2Blank(day2) + "]]></Day2>");
        buf.append("</Time>");
        if (reportConstructSchedule != null && reportConstructSchedule.size() > 0) {
            
            for (ReportConstructSchedule reportConstructSchedule2 : reportConstructSchedule)
            {
                Date date = reportConstructSchedule2.getCutOffDtm();
                String cutOffDtm = dateUtil.convertDate(date);
                buf.append("<Record>"
                    + "<processNumber><![CDATA[" + this.null2Blank(reportConstructSchedule2.getProcessNumber()) + "]]></processNumber>"
                    +"<cutOffDtm><![CDATA[" + this.null2Blank(cutOffDtm) + "]]></cutOffDtm>"
                    + "</Record>");
            }
        }
        buf.append("</reportConstructSchedule>");
        
        buf.append("<reportMaterial1>");
        buf.append("<Title>进场主要工程材料、构配件和设备汇总</Title>");
        buf.append("</reportMaterial1>");
        
        buf.append("<reportMaterial>");
        Integer j = 0;
        if (reportMaterial != null && reportMaterial.size() > 0) {
            
            for (ReportMaterial reportMaterial2 : reportMaterial)
            {
                Boolean certificate = reportMaterial2.getCertificate();
                String certificate1 = null;
                if (certificate == false)
                {
                    certificate1 = "否";
                }
                else{
                    certificate1 = "是";
                }
                j++;
                buf.append("<Record>"
                    + "<number><![CDATA[" + this.null2Blank(j+"") + "]]></number>"
                    +"<name><![CDATA[" + this.null2Blank(reportMaterial2.getName()) + "]]></name>"
                    + "<supplySituation><![CDATA[" + this.null2Blank(reportMaterial2.getSupplySituation()) + "]]></supplySituation>"
                    +"<certificate><![CDATA[" + this.null2Blank(certificate1) + "]]></certificate>"
                    + "<manufacturer><![CDATA[" + this.null2Blank(reportMaterial2.getManufacturer()) + "]]></manufacturer>"
                    + "<unit><![CDATA[" + this.null2Blank(reportMaterial2.getUnit()) + "]]></unit>"
                    + "<amount><![CDATA[" + this.null2Blank(reportMaterial2.getAmount()+"") + "]]></amount>"
                    + "<sampledResult><![CDATA[" + this.null2Blank(reportMaterial2.getSampledResult()) + "]]></sampledResult>"
                    + "</Record>");
            }
        }
        buf.append("</reportMaterial>");
        
        buf.append("<weekly>");
        buf.append("<actualConstructionSite><![CDATA[" +this.null2Blank(weeklyDTO.getActualConstructionSite()) + "]]></actualConstructionSite>");
        buf.append("<safeCivilizeProduct><![CDATA[" +this.null2Blank(weeklyDTO.getSafeCivilizeProduct()) + "]]></safeCivilizeProduct>");
        buf.append("<problemTreatMeasure><![CDATA[" +this.null2Blank(weeklyDTO.getProblemTreatMeasure()) + "]]></problemTreatMeasure>");
        buf.append("<ReportPeopleNumber>");
        buf.append("<executive><![CDATA[" +this.null2Blank(reportPeopleNumber.getExecutive()+"") + "]]></executive>");
        buf.append("<woodworker><![CDATA[" +this.null2Blank(reportPeopleNumber.getWoodworker()+"") + "]]></woodworker>");
        buf.append("<bricklayer><![CDATA[" +this.null2Blank(reportPeopleNumber.getBricklayer()+"") + "]]></bricklayer>");
        buf.append("<installer><![CDATA[" +this.null2Blank(reportPeopleNumber.getInstaller()+"") + "]]></installer>");
        buf.append("<other><![CDATA[" +this.null2Blank(reportPeopleNumber.getOther()+"") + "]]></other>");
        buf.append("</ReportPeopleNumber>");
        
        buf.append("<ReportChronicle>");
        buf.append("<content><![CDATA[" +this.null2Blank(reportChronicle.getContent()) + "]]></content>");
        buf.append("</ReportChronicle>");
        
        buf.append("</weekly>");
        
        buf.append(" <people>");
        buf.append("<creatByName><![CDATA[" +this.null2Blank(weekReportDTO.getCreatByName()) + "]]></creatByName>");
        buf.append(" </people>");
        
        buf.append(" <ReportFooter>");
        buf.append(" </ReportFooter>");
        buf.append("</weekReport>");
        pdf_url = pdfGeneratorForWeeklyReport(buf, pdfFileName.toString(), localPath + "/fop_config");
        return pdf_url;
    }
    
    private String pdfGeneratorForWeeklyReport(StringBuffer buf, String pdfFileName, String fopConfigPath)  throws IOException{
        String pdf_url = null;
        ReportData data = null;
        FileOutputStream fos = null;
        File file = new File(fopConfigPath + "/report/fop_xsl/weekReport.xsl");
        if (file != null) {
            try {
                data = FopReport.createReport(file.toString(), buf.toString().getBytes("UTF-8"), fopConfigPath);
                fos = new FileOutputStream(localPath + "/" + pdfFileName);
                pdf_url = remotePath + "/" + pdfFileName;
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (data != null) {
                    fos.write(data.getData());
                    fos.close();
                }
            }
        }
        return pdf_url;
    }
    
    private String null2Blank(String str) {
        String result = "";
        if (StringUtils.isNotBlank(str)) {
            result = str;
        }
        return result;
    }
    
    private String getPDFRemotePath(String fileName){
        return new StringBuilder().append(remotePath).append(File.separator).append(fileName).toString();
    }
    
    @Override
    public void setEnvironment(Environment environment) {
        propertyResolver = new RelaxedPropertyResolver(environment, ENV_FILE_PATH);
        localPath = propertyResolver.getProperty(LOCAL_PATH, String.class, null);
        remotePath = propertyResolver.getProperty(REMOTE_PATH, String.class, null);
        
    }
    
    @Override
    public String getReportDayPDF(int id)
        throws BusinessException, IOException
    {
        String pdf_url = null;
        StringBuffer pdfFileName = new StringBuffer();
        pdfFileName
        .append("DayReport").append("-").append(System.currentTimeMillis()).append(".pdf");
        pdf_url = getPDFRemotePath(pdfFileName.toString());
        DateUtil dateUtil = new DateUtil();
        
        WeeklyDTO weeklyDTO = weeklyReadMapper.selectPrimaryKey(id);
        //取出时间
        Date createdDtm = weeklyDTO.getCreatedDtm();
        String year = dateUtil.convertYear(createdDtm);
        String month = dateUtil.getMm(createdDtm);
        String day = dateUtil.getDd(createdDtm);
        Date createdDtm1 = dateUtil.getNextDayTime(createdDtm);
        String month1 = dateUtil.getMm(createdDtm1);
        String day1 = dateUtil.getDd(createdDtm1);
        //String year1 = dateUtil.convertYear(createdDtm1);
        
        Integer remouldProjectId = weeklyDTO.getRemouldProjectId();
        WeekReportDTO weekReportDTO = weeklyReadMapper.getWeekReportDTO(remouldProjectId);
        //取出编号
        String serialNum = weekReportDTO.getSerialNum();
        
        Weather weather = weatherReadMapper.selectByDayId(id);
        Integer sun = weather.getSunny();
       
        Integer cloudy = weather.getCloudy();
      
        Integer rain = weather.getRain();
      
        List<WeekCompleteWork> weekCompleteWork = weekCompleteWorkReadMapper.selectByDayId(id);
        List<ReportMaterial> reportMaterial = reportMaterialReadMapper.selectByDayId(id+"");
        
        ReportPeopleNumber reportPeopleNumber = reportPeopleNumberReadMapper.selectByDayId(id);
        ReportChronicle reportChronicle = reportChronicleReadMapper.selectByDayId(id+"");
        List<ReportConstructSchedule> reportConstructSchedule = reportConstructScheduleReadMapper.selectByDayId(id);
        
        //填充数据
        StringBuffer buf = new StringBuffer();
        buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        buf.append("<dayReport>");
        
        buf.append(" <ReportHeader>");
        buf.append("<Title>");
        buf.append("<RemouldProjectName><![CDATA[" +this.null2Blank(weekReportDTO.getName()) + "]]></RemouldProjectName>");
        buf.append("</Title>");
        buf.append(" </ReportHeader>");
        
        buf.append("<ReportTime>");
        buf.append("<Time>");
        buf.append("<Year><![CDATA[" +this.null2Blank(year) + "]]></Year>");
        buf.append("<Month><![CDATA[" +this.null2Blank(month) + "]]></Month>");
        buf.append("<Day><![CDATA[" +this.null2Blank(day) + "]]></Day>");
        buf.append("<SerialNum><![CDATA[" +this.null2Blank(serialNum) + "]]></SerialNum>");
        buf.append("</Time>");
        buf.append("</ReportTime>");
        
        buf.append("<ReportWeather>");
        buf.append("<Weather>");
        buf.append("<Sun><![CDATA[" +this.null2Blank(sun+"") + "]]></Sun>");
        buf.append("<Cloudy><![CDATA[" +this.null2Blank(cloudy+"") + "]]></Cloudy>");
        buf.append("<Rain><![CDATA[" +this.null2Blank(rain+"") + "]]></Rain>");
        buf.append("</Weather>");
        buf.append("</ReportWeather>");
        
        buf.append("<WeekCompleteWork1>");
        buf.append("<Title>本日各部分项工程完成情况</Title>");
        buf.append("</WeekCompleteWork1>");
        
        buf.append("<WeekCompleteWork>");
        Integer i = 0;
        if (weekCompleteWork != null && weekCompleteWork.size() > 0) {
            
            for (WeekCompleteWork weekCompleteWork2 : weekCompleteWork)
            {
                i++;
                buf.append("<Record>"
                    + "<number><![CDATA[" + this.null2Blank(i+"") + "]]></number>"
                    +"<remouldProjectName><![CDATA[" + this.null2Blank(weekReportDTO.getName()) + "]]></remouldProjectName>"
                    + "<constructContent><![CDATA[" + this.null2Blank(weekCompleteWork2.getConstructContent()) + "]]></constructContent>"
                    +"<constructUnit><![CDATA[" + this.null2Blank(weekReportDTO.getConstructUnit()) + "]]></constructUnit>"
                    + "<plannCompleteWork><![CDATA[" + this.null2Blank(weekCompleteWork2.getPlannCompleteWork()+"") + "]]></plannCompleteWork>"
                    + "<actualCompleteWork><![CDATA[" + this.null2Blank(weekCompleteWork2.getActualCompleteWork()+"") + "]]></actualCompleteWork>"
                    + "<comment><![CDATA[" + this.null2Blank(weekCompleteWork2.getComment()) + "]]></comment>"
                    + "</Record>");
            }  
        }
        buf.append("</WeekCompleteWork>");
        
        buf.append("<reportConstructSchedule1>");
        buf.append("<Title>下一天的施工进度计划表</Title>");
        buf.append("</reportConstructSchedule1>");
        
        buf.append("<reportConstructSchedule>");
        buf.append("<Time>");
        buf.append("<Month1><![CDATA[" +this.null2Blank(month1) + "]]></Month1>");
        buf.append("<Day1><![CDATA[" +this.null2Blank(day1) + "]]></Day1>");
        buf.append("</Time>");
        if (reportConstructSchedule != null && reportConstructSchedule.size() > 0) {
            
            for (ReportConstructSchedule reportConstructSchedule2 : reportConstructSchedule)
            {
                Date date = reportConstructSchedule2.getCutOffDtm();
                String cutOffDtm = dateUtil.convertDate(date);
                buf.append("<Record>"
                    + "<processNumber><![CDATA[" + this.null2Blank(reportConstructSchedule2.getProcessNumber()) + "]]></processNumber>"
                    +"<cutOffDtm><![CDATA[" + this.null2Blank(cutOffDtm) + "]]></cutOffDtm>"
                    + "</Record>");
            }
        }
        buf.append("</reportConstructSchedule>");
        
        buf.append("<reportMaterial1>");
        buf.append("<Title>进场主要工程材料、构配件和设备汇总</Title>");
        buf.append("</reportMaterial1>");
        
        buf.append("<reportMaterial>");
        Integer j = 0;
        if (reportMaterial != null && reportMaterial.size() > 0) {
            
            for (ReportMaterial reportMaterial2 : reportMaterial)
            {
                Boolean certificate = reportMaterial2.getCertificate();
                String certificate1 = null;
                if (certificate == false)
                {
                    certificate1 = "否";
                }
                else{
                    certificate1 = "是";
                }
                j++;
                buf.append("<Record>"
                    + "<number><![CDATA[" + this.null2Blank(j+"") + "]]></number>"
                    +"<name><![CDATA[" + this.null2Blank(reportMaterial2.getName()) + "]]></name>"
                    + "<supplySituation><![CDATA[" + this.null2Blank(reportMaterial2.getSupplySituation()) + "]]></supplySituation>"
                    +"<certificate><![CDATA[" + this.null2Blank(certificate1) + "]]></certificate>"
                    + "<manufacturer><![CDATA[" + this.null2Blank(reportMaterial2.getManufacturer()) + "]]></manufacturer>"
                    + "<unit><![CDATA[" + this.null2Blank(reportMaterial2.getUnit()) + "]]></unit>"
                    + "<amount><![CDATA[" + this.null2Blank(reportMaterial2.getAmount()+"") + "]]></amount>"
                    + "<sampledResult><![CDATA[" + this.null2Blank(reportMaterial2.getSampledResult()) + "]]></sampledResult>"
                    + "</Record>");
            }
        }
        buf.append("</reportMaterial>");
        
        buf.append("<weekly>");
        buf.append("<actualConstructionSite><![CDATA[" +this.null2Blank(weeklyDTO.getActualConstructionSite()) + "]]></actualConstructionSite>");
        buf.append("<safeCivilizeProduct><![CDATA[" +this.null2Blank(weeklyDTO.getSafeCivilizeProduct()) + "]]></safeCivilizeProduct>");
        buf.append("<problemTreatMeasure><![CDATA[" +this.null2Blank(weeklyDTO.getProblemTreatMeasure()) + "]]></problemTreatMeasure>");
        buf.append("<ReportPeopleNumber>");
        buf.append("<executive><![CDATA[" +this.null2Blank(reportPeopleNumber.getExecutive()+"") + "]]></executive>");
        buf.append("<woodworker><![CDATA[" +this.null2Blank(reportPeopleNumber.getWoodworker()+"") + "]]></woodworker>");
        buf.append("<bricklayer><![CDATA[" +this.null2Blank(reportPeopleNumber.getBricklayer()+"") + "]]></bricklayer>");
        buf.append("<installer><![CDATA[" +this.null2Blank(reportPeopleNumber.getInstaller()+"") + "]]></installer>");
        buf.append("<other><![CDATA[" +this.null2Blank(reportPeopleNumber.getOther()+"") + "]]></other>");
        buf.append("</ReportPeopleNumber>");
        
        buf.append("<ReportChronicle>");
        buf.append("<content><![CDATA[" +this.null2Blank(reportChronicle.getContent()) + "]]></content>");
        buf.append("</ReportChronicle>");
        
        buf.append("</weekly>");
        
        buf.append(" <people>");
        buf.append("<creatByName><![CDATA[" +this.null2Blank(weekReportDTO.getCreatByName()) + "]]></creatByName>");
        buf.append(" </people>");
        
        buf.append(" <ReportFooter>");
        buf.append(" </ReportFooter>");
        buf.append("</dayReport>");
        pdf_url = pdfGeneratorForDayReport(buf, pdfFileName.toString(), localPath + "/fop_config");
        return pdf_url;
    }
    
    private String pdfGeneratorForDayReport(StringBuffer buf, String pdfFileName, String fopConfigPath)  throws IOException{
        String pdf_url = null;
        ReportData data = null;
        FileOutputStream fos = null;
        File file = new File(fopConfigPath + "/report/fop_xsl/dayReport.xsl");
        if (file != null) {
            try {
                data = FopReport.createReport(file.toString(), buf.toString().getBytes("UTF-8"), fopConfigPath);
                fos = new FileOutputStream(localPath + "/" + pdfFileName);
                pdf_url = remotePath + "/" + pdfFileName;
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (data != null) {
                    fos.write(data.getData());
                    fos.close();
                }
            }
        }
        return pdf_url;
    }

    @Override
    public String getReportMonthPDF(int id)
        throws BusinessException, IOException
    {
        String pdf_url = null;
        StringBuffer pdfFileName = new StringBuffer();
        pdfFileName
        .append("MonthReport").append("-").append(System.currentTimeMillis()).append(".pdf");
        pdf_url = getPDFRemotePath(pdfFileName.toString());
        DateUtil dateUtil = new DateUtil();
        //从数据库取值
        MonthlyDTO monthlyDTO = monthlyReadMapper.selectPrimaryKey(id);
        String year = monthlyDTO.getMonth().substring(0,4);
        String month7 = monthlyDTO.getMonth();
        String month = month7.substring(5);
        Date startDate = dateUtil.getLastMonthTime(monthlyDTO.getCreatedDtm());
        String year1 = dateUtil.convertYear(startDate);
        String month1 = dateUtil.getMm(startDate);
        String day = dateUtil.getDd(startDate);
        String day1 = dateUtil.getDd(monthlyDTO.getCreatedDtm());
        String duration = year1+"年"+month1+"月"+day+"日~"+month+"月"+day1+"日";
        String createdDtm = year1+"年"+month+"月"+day1+"日";
        //取出资料
        String[] idArr = monthlyDTO.getEngineerData().split(",");
        String[] name=new String[idArr.length];
        for (String string : idArr)
        {
            int i =0;
            Integer engineerId = Integer.parseInt(string);
            SystemFile file = fileReadMapper.selectByPrimaryKey(engineerId);
            String fileName = file.getName();
            name[i] = fileName;
            i++;
        }
        String dataName = null;
        StringBuffer sBuffer = new StringBuffer();
        for (String fileName : name)
        {
            sBuffer.append(fileName+"    ");
        }
        dataName = sBuffer.toString();
        Date nextDay = dateUtil.getNextDayTime(monthlyDTO.getCreatedDtm());
        String month4 = dateUtil.getMm(nextDay);
        String day4 = dateUtil.getDd(nextDay);
        Date nextMonth = dateUtil.getNextMonthTime(nextDay);
        String month3 = dateUtil.getMm(nextMonth);
        String day3 = dateUtil.getDd(nextMonth);
        
        Integer remouldProjectId = monthlyDTO.getRemouldProjectId();
        WeekReportDTO weekReportDTO = weeklyReadMapper.getWeekReportDTO(remouldProjectId);
        RemouldProjectDTO remouldProjectDTO = remouldProjectReadMapper.selectDTOByPrimaryKey(remouldProjectId);
        PropertyDTO propertyDTO = remouldProjectDTO.getPropertyDTO();
        if (remouldProjectDTO != null && propertyDTO != null) {
            buildAddressDTO(propertyDTO);
        }
        weekReportDTO.setProjectAddress(propertyDTO);
        
        List<ReportChronicle> reportChronicle = reportChronicleReadMapper.selectByMonthlyId(id+"");
        Weather weather = weatherReadMapper.selectByMonthlyId(id);
        List<MonthCompleteWork> monthCompleteWork = monthCompleteWorkReadMapper.selectByMonthlyId(id);
        List<ReportConstructSchedule> reportConstructSchedule = reportConstructScheduleReadMapper.selectByMonthlyId(id);
        List<ReportMaterial> reportMaterial = reportMaterialReadMapper.selectByMonthlyId(id+"");
        List<ReportFund> reportFund = reportFundReadMapper.selectByMonthlyId(id);
        List<ReportDesignEngineer> reportDesignEngineer = reportDesignEngineerReadMapper.selectByMonthlyId(id);
        List<ReportConstructPeople> reportConstructPeople = reportConstructPeopleReadMapper.selectByMonthlyId(id);
        List<ReportConstructPhoto> reportConstructPhoto = reportConstructPhotoReadMapper.selectByMonthlyId(id);
        //填充值
        StringBuffer buf = new StringBuffer();
        buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        buf.append("<monthReport>");
        
        buf.append(" <ReportHeader>");
        buf.append("<Title>");
        buf.append("<year><![CDATA[" +this.null2Blank(year) + "]]></year>");
        buf.append("<month><![CDATA[" +this.null2Blank(month) + "]]></month>");
        buf.append("</Title>");
        buf.append(" </ReportHeader>");
        
        buf.append(" <ReportHeader1>");
        buf.append("<Content>");
        buf.append("<name><![CDATA[" +this.null2Blank(weekReportDTO.getName()) + "]]></name>");
        buf.append("</Content>");
        buf.append(" </ReportHeader1>");
        
        buf.append(" <ReportHeader2>");
        buf.append("<Content>");
        buf.append("<duration><![CDATA[" +this.null2Blank(duration) + "]]></duration>");
        buf.append("</Content>");
        buf.append(" </ReportHeader2>");
        
        buf.append(" <ReportHeader3>");
        buf.append("<Content>");
        buf.append("<creatByName><![CDATA[" +this.null2Blank(weekReportDTO.getCreatByName()) + "]]></creatByName>");
        buf.append("</Content>");
        buf.append(" </ReportHeader3>");
        
        buf.append(" <ReportHeader4>");
        buf.append("<Content>");
        buf.append("<cityManager><![CDATA[" +this.null2Blank(weekReportDTO.getCityManager()) + "]]></cityManager>");
        buf.append("</Content>");
        buf.append(" </ReportHeader4>");
        
        buf.append(" <ReportHeader5>");
        buf.append("<Content>");
        buf.append("<createdDtm><![CDATA[" +this.null2Blank(createdDtm) + "]]></createdDtm>");
        buf.append("</Content>");
        buf.append(" </ReportHeader5>");
        
        buf.append(" <ProjectOverview>");
        buf.append("<Content>");
        buf.append("<name><![CDATA[" +this.null2Blank(weekReportDTO.getName()) + "]]></name>");
        buf.append("<projectAddress><![CDATA[" +this.null2Blank(weekReportDTO.getProjectAddress().getAddressDto().getFullAddress()) + "]]></projectAddress>");
        buf.append("<constructUnit><![CDATA[" +this.null2Blank(weekReportDTO.getConstructUnit()) + "]]></constructUnit>");
        buf.append("</Content>");
        buf.append(" </ProjectOverview>");
        
        buf.append("<ReportChronicle>");
        if (reportChronicle != null && reportChronicle.size() > 0) {            
            for (ReportChronicle reportChronicle2 : reportChronicle)
            {
                String month2 = dateUtil.getMm(reportChronicle2.getOccurrTime());
                String day2 = dateUtil.getDd(reportChronicle2.getOccurrTime());
                String date = month2+"."+day2;
                buf.append("<Record>"
                    + "<date><![CDATA[" + this.null2Blank(date) + "]]></date>"
                    +"<content><![CDATA[" + this.null2Blank(reportChronicle2.getContent()) + "]]></content>"
                    + "</Record>");
            }
        }
        buf.append("</ReportChronicle>");
        
        buf.append(" <ReportWeather>");
        buf.append("<Weather>");
        buf.append("<month><![CDATA[" +this.null2Blank(month1) + "]]></month>");
        buf.append("<day><![CDATA[" +this.null2Blank(day) + "]]></day>");
        buf.append("<month1><![CDATA[" +this.null2Blank(month) + "]]></month1>");
        buf.append("<day1><![CDATA[" +this.null2Blank(day1) + "]]></day1>");
        buf.append("<totalDay><![CDATA[" +this.null2Blank(weather.getTotalDay()+"") + "]]></totalDay>");
        buf.append("<sunny><![CDATA[" +this.null2Blank(weather.getSunny()+"") + "]]></sunny>");
        buf.append("<cloudy><![CDATA[" +this.null2Blank(weather.getCloudy()+"") + "]]></cloudy>");
        buf.append("<rain><![CDATA[" +this.null2Blank(weather.getRain()+"") + "]]></rain>");
        buf.append("<maxTemperature><![CDATA[" +this.null2Blank(weather.getMaxTemperature()) + "]]></maxTemperature>");
        buf.append("<minTemperature><![CDATA[" +this.null2Blank(weather.getMinTemperature()) + "]]></minTemperature>");
        buf.append("<other><![CDATA[" +this.null2Blank(weather.getOther()+"") + "]]></other>");
        buf.append("</Weather>");
        buf.append(" </ReportWeather>");
        
        buf.append(" <MonthCompleteWork>");
        Integer i = 0;
        if (monthCompleteWork != null && monthCompleteWork.size() > 0) {
            
            for (MonthCompleteWork monthCompleteWork2 : monthCompleteWork)
            {
                i++;
                buf.append("<Record>"
                    + "<number><![CDATA[" + this.null2Blank(i+"") + "]]></number>"
                    +"<remouldProjectName><![CDATA[" + this.null2Blank(weekReportDTO.getName()) + "]]></remouldProjectName>"
                    + "<constructContent><![CDATA[" + this.null2Blank(monthCompleteWork2.getConstructContent()) + "]]></constructContent>"
                    +"<constructUnit><![CDATA[" + this.null2Blank(weekReportDTO.getConstructUnit()) + "]]></constructUnit>"
                    + "<completeWork><![CDATA[" + this.null2Blank(monthCompleteWork2.getCompleteWork()+"") + "]]></completeWork>"
                    + "<totalCompleteWork><![CDATA[" + this.null2Blank(monthCompleteWork2.getTotalCompleteWork()+"") + "]]></totalCompleteWork>"
                    + "<comment><![CDATA[" + this.null2Blank(monthCompleteWork2.getComment()) + "]]></comment>"
                    + "</Record>");
            }  
        }
        buf.append(" </MonthCompleteWork>");
        
        buf.append(" <ReportConstructSchedule>");
        buf.append("<Time>");
        buf.append("<Month1><![CDATA[" +this.null2Blank(month4) + "]]></Month1>");
        buf.append("<Day1><![CDATA[" +this.null2Blank(day4) + "]]></Day1>");
        buf.append("<Month2><![CDATA[" +this.null2Blank(month3) + "]]></Month2>");
        buf.append("<Day2><![CDATA[" +this.null2Blank(day3) + "]]></Day2>");
        buf.append("</Time>");
        if (reportConstructSchedule != null && reportConstructSchedule.size() > 0) {
            
            for (ReportConstructSchedule reportConstructSchedule2 : reportConstructSchedule)
            {
                Date date = reportConstructSchedule2.getCutOffDtm();
                String cutOffDtm = dateUtil.convertDate(date);
                buf.append("<Record>"
                    + "<processNumber><![CDATA[" + this.null2Blank(reportConstructSchedule2.getProcessNumber()) + "]]></processNumber>"
                    +"<cutOffDtm><![CDATA[" + this.null2Blank(cutOffDtm) + "]]></cutOffDtm>"
                    + "</Record>");
            }
        }
        buf.append(" </ReportConstructSchedule>");
        
        buf.append("<ReportMaterial>");
        Integer j = 0;
        if (reportMaterial != null && reportMaterial.size() > 0) {
            
            for (ReportMaterial reportMaterial2 : reportMaterial)
            {
                Boolean certificate = reportMaterial2.getCertificate();
                String certificate1 = null;
                if (certificate == false)
                {
                    certificate1 = "否";
                }
                else{
                    certificate1 = "是";
                }
                j++;
                buf.append("<Record>"
                    + "<number><![CDATA[" + this.null2Blank(j+"") + "]]></number>"
                    +"<name><![CDATA[" + this.null2Blank(reportMaterial2.getName()) + "]]></name>"
                    + "<supplySituation><![CDATA[" + this.null2Blank(reportMaterial2.getSupplySituation()) + "]]></supplySituation>"
                    +"<certificate><![CDATA[" + this.null2Blank(certificate1) + "]]></certificate>"
                    + "<manufacturer><![CDATA[" + this.null2Blank(reportMaterial2.getManufacturer()) + "]]></manufacturer>"
                    + "<unit><![CDATA[" + this.null2Blank(reportMaterial2.getUnit()) + "]]></unit>"
                    + "<amount><![CDATA[" + this.null2Blank(reportMaterial2.getAmount()+"") + "]]></amount>"
                    + "<sampledResult><![CDATA[" + this.null2Blank(reportMaterial2.getSampledResult()) + "]]></sampledResult>"
                    + "</Record>");
            }
        }
        buf.append("</ReportMaterial>");
        
        buf.append(" <MonthReport>");
        buf.append("<Content>");
        buf.append("<nextMonthSupplySchedule><![CDATA[" +this.null2Blank(monthlyDTO.getNextMonthSupplySchedule()) + "]]></nextMonthSupplySchedule>");
        buf.append("<constructionProgress><![CDATA[" +this.null2Blank(monthlyDTO.getConstructionProgress()) + "]]></constructionProgress>");
        buf.append("<constructionQuality><![CDATA[" +this.null2Blank(monthlyDTO.getConstructionQuality()) + "]]></constructionQuality>");
        buf.append("<engineeringQuantityProjectAllocation><![CDATA[" +this.null2Blank(monthlyDTO.getEngineeringQuantityProjectAllocation()) + "]]></engineeringQuantityProjectAllocation>");
        buf.append("<paymentOfWorks><![CDATA[" +this.null2Blank(monthlyDTO.getPaymentOfWorks()) + "]]></paymentOfWorks>");
        buf.append("</Content>");
        
        Integer a = 0;
        if (reportFund != null && reportFund.size() > 0) {
            
            for (ReportFund reportFund2 : reportFund)
            {
                a++;
                buf.append("<Record>"
                    + "<number><![CDATA[" +this.null2Blank(a+"") + "]]></number>"
                    +"<projectName><![CDATA[" +this.null2Blank(reportFund2.getProjectName()) + "]]></projectName>"
                    + "<filedAmount><![CDATA[" +this.null2Blank(reportFund2.getFiledAmount()+"") + "]]></filedAmount>"
                    + "<approvalAmount><![CDATA[" +this.null2Blank(reportFund2.getApprovalAmount()+"") + "]]></approvalAmount>"
                    +"<actualPay><![CDATA[" +this.null2Blank(reportFund2.getActualPay()+"") + "]]></actualPay>"
                    + "<comment><![CDATA[" + this.null2Blank(reportFund2.getComment()) + "]]></comment>"
                    + "</Record>");
            }  
        }
        
        buf.append(" </MonthReport>");
        
        buf.append(" <MattersOfContract>");
        buf.append("<Content>");
        buf.append("<projectPostponement><![CDATA[" +this.null2Blank(monthlyDTO.getProjectPostponement()) + "]]></projectPostponement>");
        buf.append("<costClaim><![CDATA[" +this.null2Blank(monthlyDTO.getCostClaim()) + "]]></costClaim>");
        buf.append("</Content>");
        
        Integer b = 0;
        if (reportDesignEngineer != null && reportDesignEngineer.size() > 0) {
            
            for (ReportDesignEngineer reportDesignEngineer2 : reportDesignEngineer)
            {
                b++;
                String year5 = dateUtil.convertYear(reportDesignEngineer2.getReceviedDtm());
                String month5 = dateUtil.getMm(reportDesignEngineer2.getReceviedDtm());
                String day5 = dateUtil.getDd(reportDesignEngineer2.getReceviedDtm());
                String receviedDtm = year5+"."+month5+"."+day5;
                String year6 = dateUtil.convertYear(reportDesignEngineer2.getSendDtm());
                String month6 = dateUtil.getMm(reportDesignEngineer2.getSendDtm());
                String day6 = dateUtil.getDd(reportDesignEngineer2.getSendDtm());
                String sendDtm = year6+"."+month6+"."+day6;
                buf.append("<Record>"
                    + "<number><![CDATA[" +this.null2Blank(b+"") + "]]></number>"
                    +"<name><![CDATA[" +this.null2Blank(reportDesignEngineer2.getName()) + "]]></name>"
                    + "<serialNumber><![CDATA[" +this.null2Blank(reportDesignEngineer2.getSerialNumber()) + "]]></serialNumber>"
                    + "<receviedDtm><![CDATA[" +this.null2Blank(receviedDtm) + "]]></receviedDtm>"
                    +"<sendDtm><![CDATA[" +this.null2Blank(sendDtm) + "]]></sendDtm>"
                    + "<comment><![CDATA[" + this.null2Blank(reportDesignEngineer2.getComment()) + "]]></comment>"
                    + "</Record>");
            }  
        }
        buf.append(" </MattersOfContract>");
        
        buf.append(" <SafeProductionCivilizedConstruction>");
        buf.append("<Content>");
        buf.append("<safeCivilizeProduct><![CDATA[" +this.null2Blank(monthlyDTO.getSafeCivilizeProduct()) + "]]></safeCivilizeProduct>");
        buf.append("<totalPeople><![CDATA[" +this.null2Blank(monthlyDTO.getTotalPeople()+"") + "]]></totalPeople>");
        buf.append("<managerPeople><![CDATA[" +this.null2Blank(monthlyDTO.getManagerPeople()+"") + "]]></managerPeople>");
        buf.append("<workPeople><![CDATA[" +this.null2Blank(monthlyDTO.getWorkPeople()+"") + "]]></workPeople>");
        buf.append("</Content>");
        
        Integer c = 1;
        if (reportConstructPeople != null && reportConstructPeople.size() > 0) {
            
            for (ReportConstructPeople reportConstructPeople2 : reportConstructPeople)
            {
                Boolean certificate = reportConstructPeople2.getCertificated();
                String certificate1 = null;
                if (certificate == false)
                {
                    certificate1 = "否";
                }
                else{
                    certificate1 = "是";
                }
                Boolean safetyEducation = reportConstructPeople2.getSafetyEducation();
                String safetyEducation1 = null;
                if (safetyEducation == false)
                {
                    safetyEducation1 = "否";
                }
                else{
                    safetyEducation1 = "是";
                }
                buf.append("<Record>"
                    + "<number><![CDATA[" +this.null2Blank(c+"") + "]]></number>"
                    +"<subcontractor><![CDATA[" +this.null2Blank(reportConstructPeople2.getSubcontractor()) + "]]></subcontractor>"
                    + "<job><![CDATA[" +this.null2Blank(reportConstructPeople2.getJob()) + "]]></job>"
                    + "<peopleNumber><![CDATA[" +this.null2Blank(reportConstructPeople2.getPeopleNumber()+"") + "]]></peopleNumber>"
                    +"<certificated><![CDATA[" +this.null2Blank(certificate1) + "]]></certificated>"
                    +"<safetyEducation><![CDATA[" +this.null2Blank(safetyEducation1) + "]]></safetyEducation>"
                    +"<enterExit><![CDATA[" +this.null2Blank(reportConstructPeople2.getEnterExit()) + "]]></enterExit>"
                    + "<comment><![CDATA[" + this.null2Blank(reportConstructPeople2.getComment()) + "]]></comment>"
                    + "</Record>");
            }  
        }
        buf.append(" </SafeProductionCivilizedConstruction>");
        
        buf.append(" <EngineeringTechnicalInformation>");
        buf.append("<Content>");
        buf.append("<name><![CDATA[" +this.null2Blank(dataName) + "]]></name>");
        buf.append("</Content>");
        buf.append(" </EngineeringTechnicalInformation>");
        
        buf.append(" <CoordinationMatters>");
        buf.append("<Content>");
        buf.append("<coordinationMatters><![CDATA[" +this.null2Blank(monthlyDTO.getCoordinationMatters()) + "]]></coordinationMatters>");
        buf.append("<technologyInnovation><![CDATA[" +this.null2Blank(monthlyDTO.getTechnologyInnovation()) + "]]></technologyInnovation>");
        buf.append("</Content>");
        buf.append(" </CoordinationMatters>");
        
        buf.append(" <ReportConstructPhoto>");

        buf.append(" </ReportConstructPhoto>");
        
        buf.append(" <ReportFooter>");
        buf.append(" </ReportFooter>");
        
        buf.append("</monthReport>");
        pdf_url = pdfGeneratorForMonthReport(buf, pdfFileName.toString(), localPath + "/fop_config");
        return pdf_url;
    }
    private String pdfGeneratorForMonthReport(StringBuffer buf, String pdfFileName, String fopConfigPath)  throws IOException{
        String pdf_url = null;
        ReportData data = null;
        FileOutputStream fos = null;
        File file = new File(fopConfigPath + "/report/fop_xsl/monthReport.xsl");
        if (file != null) {
            try {
                data = FopReport.createReport(file.toString(), buf.toString().getBytes("UTF-8"), fopConfigPath);
                fos = new FileOutputStream(localPath + "/" + pdfFileName);
                pdf_url = remotePath + "/" + pdfFileName;
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (data != null) {
                    fos.write(data.getData());
                    fos.close();
                }
            }
        }
        return pdf_url;
    }
}
